﻿using BaseUI;
using BLL;
using Model;
using System;
using System.Data;

namespace Thksoft.BusinessExpansion.Templete
{
    public partial class Upd_HeadSetting : BasePage
    {
        private Qs_HeadBLL qhb = new Qs_HeadBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable model = qhb.GetModelById(Request.QueryString["ID"].ToString());
                if (model != null && model.Rows.Count > 0)
                {
                    foreach (DataRow item in model.Rows)
                    {
                        comId.Value = item["CMY_ID"].ToString();
                        txtCompany.Text = item["CMY_NAME"].ToString();
                        txtCw.Text = item["FIN_DIRECTOR"].ToString();
                        txtFzr.Text = item["USER_ID"].ToString();
                    }
                }
                else
                {
                    comId.Value = "-1";
                }

                lblCzRen.Text = lognUser.USER_NAME;
                lblCzTime.Text = DateTime.Now.ToString();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Qs_Head model = new Qs_Head();

            if (string.IsNullOrEmpty(txtCw.Text.Trim()))
            {
                MessageBox.Show(Page, "请选择公司财务负责人");
                return;
            }
            if (string.IsNullOrEmpty(txtFzr.Text.Trim()))
            {
                MessageBox.Show(Page, "请选择公司负责人");
                return;
            }

            model.CMY_ID = decimal.Parse(Request.QueryString["ID"].ToString());
            model.USER_ID = txtFzr.Text.Trim();
            model.FIN_DIRECTOR = txtCw.Text.Trim();
            model.OPER_PEOPLE = lognUser.USER_ID;

            if (qhb.UpdateModel(model, "") > 0)
            {
                MessageBox.Show(Page, "保存成功");
                return;
            }
            else
            {
                MessageBox.Show(Page, "保存失败");
                return;
            }
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("HeadSetting.aspx");
        }
    }
}